package com.itheima.JDBC.C3p0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class demo {
    public static void main(String[] args) throws PropertyVetoException {
        ComboPooledDataSource spds = new ComboPooledDataSource();
        spds.setDriverClass("com.mysql.jdbc.Driver");
        spds.setJdbcUrl("jdbc:mysql://localhost:3306/heima");
        spds.setUser("root");
        spds.setPassword("root");

        String sql = "select * from emp";
        try (
                Connection con = spds.getConnection();
                PreparedStatement statement = con.prepareStatement(sql);
                ResultSet resultSet = statement.executeQuery();
        ) {
            while (resultSet.next()) {
                System.out.println(resultSet.getString("ename"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
